#ifndef SOS_TIMER_QUEUE_H
#define SOS_TIMER_QUEUE_H

#define TIMER_OP_OK 0
#define TIMER_OP_EMPTY 1
#define TIMER_OP_FULL 2
#define TIMER_OP_OOM 3
#define TIMER_OP_COND 4

#include <clock/clock.h>

// #include <stdint.h>
// XXX These inline definitions are temporary
// typedef uint64_t timestamp_t;
// typedef void (*timer_callback_t)(uint32_t id, void *data);

typedef struct timer_node {
    timestamp_t key;
    timer_callback_t callback;
    void *data;
    uint32_t id;
    struct timer_node *next;
    struct timer_node *prev;
} timer_node;

typedef struct timer_queue {
    timer_node *head;
    int capacity;
    int size;
} *timer_queue;

timer_queue timer_queue_init(int max_capacity);
void timer_queue_free(timer_queue q);
int timer_queue_insert(timer_queue q, timestamp_t key, timer_callback_t cb,
                      void *data, uint32_t *id);
int timer_queue_min(timer_queue q, timer_node *n);
int timer_queue_min_remove(timer_queue q);
int timer_queue_conditional_pop(timer_queue q, timer_node *n, timestamp_t thresh);
int timer_queue_id_remove(timer_queue q, uint32_t id);

#endif
